package com.springboot.project.common.controller;


import com.springboot.config.annotion.BusinessLog;
import com.springboot.config.tool.PageUtils;
import com.springboot.config.tool.Tip;
import com.springboot.project.common.service.impl.GeneratorServiceImpl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@RequestMapping("/generator")
@Controller
public class GeneratorController {

	String prefix = "system/generator";
	@Autowired
	GeneratorServiceImpl generatorService;

	@RequestMapping("")
	String generator() {
		return prefix + "/generator";
	}

	@RequestMapping(value = "/list",method = RequestMethod.POST)
	@ResponseBody
	PageUtils list() {
		List<Map<String, Object>> list = generatorService.list();
		int total = list.size();
		PageUtils pageUtil = new PageUtils(list, total);
		return pageUtil;
	};

	@RequestMapping("/batchCode/{tableName}")
	@BusinessLog(value = "生成代码")
	@RequiresPermissions("/generator/batchCode")
	@ResponseBody
	public Tip batchCode(@PathVariable String tableName)  {
		generatorService.generatorCode(tableName);
		return new Tip();
	}
}
